package com.campus.controller;

import com.campus.entity.Activity;
import com.campus.service.ActivityService1;
import com.campus.web.vo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/activity")
public class ActivityController {
    @Autowired
    private ActivityService1 activityService;
@PostMapping("/add")
    public ResponseResult addActivity(@RequestBody Activity activity) {
    int i= activityService.saveActivity(activity);
    if(i>0){
        return ResponseResult.ok(i,"添加成功");
    }
else return ResponseResult.error(HttpStatus.BAD_REQUEST,"添加失败");
}
@PostMapping("/update")
    public ResponseResult updateActivity(@RequestBody Activity activity) {
    activityService.updateActivity(activity);
    return ResponseResult.ok("更新成功");
}
@PostMapping("/publish")
    public ResponseResult publishActivity(int status,int id ) {
    activityService.publishActivity(status,id);
    return ResponseResult.ok("发布成功");
}
@PostMapping("/select")
    public ResponseResult<List<Activity>> selectActivityCreate(Integer status, String name) {
    List<Activity> activities=activityService.selectActivityCreateTime(status,name);
    return ResponseResult.ok(activities,"查询成功");
}


}
